package junit;

import dao.OrderDao;
import dao.impl.OrderDaoImpl;
import org.junit.Test;
import pojo.Order;

import java.math.BigDecimal;
import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * @author Wxt
 * @create 2022-02-11 21:11
 */
public class OrderDaoTest {
    private OrderDao orderDao = new OrderDaoImpl();
    private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

    @Test
    public void saveOrder() {
        try {
            long time = simpleDateFormat.parse("2022-02-11").getTime();
            orderDao.saveOrder(new Order("123456789", new Date(time), new BigDecimal(45), 0, 2));
            System.out.println("保存成功");
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void queryOrders() {
        List<Order> orders = orderDao.queryOrders();
        orders.forEach(System.out :: println);
    }

    @Test
    public void changeOrderStatus() {
        orderDao.changeOrderStatus("123456789", 1);
        System.out.println("修改成功");
    }

    @Test
    public void queryOrdersByUserId() {
        List<Order> orders = orderDao.queryOrdersByUserId(2);
        System.out.println(orders);
    }
    @Test
    public void queryForPageTotalCount() {
        int pageTotalCount = orderDao.queryForPageTotalCount();
        System.out.println(pageTotalCount);
    }
    @Test
    public void queryForOrders() {
        List<Order> orders = orderDao.queryForOrders(0, 4);
        System.out.println(orders);
    }
}